<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/css/layui.css}"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script th:src="@{/layui.js}" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
</head>
<body><br>
<form class="layui-form" action="" id="Search">
<div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">WeChat号</label>
        <div class="layui-input-inline">
            <input type="text" name="wechat_no" id="wechat_no" autocomplete="off" class="layui-input">
        </div>
    </div>
   <div class="layui-inline">
        <label class="layui-form-label">Wechat备注</label>
        <div class="layui-input-inline">
            <input type="text" name="wechat_mark" id="wechat_mark" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">QQ</label>
        <div class="layui-input-inline">
            <input type="text" name="qq_no" id="qq_no" autocomplete="off" class="layui-input">
        </div>
    </div>
        <button type="button"  onclick="doSerach();" class="layui-btn layui-btn-sm" lay-submit="" lay-filter="demo1">Search</button>
        <button type="reset" class="layui-btn  layui-btn-sm ">Reset</button>
</div>
    </form>





<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">

    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script>
    var table;
    var $;
    layui.use('table', function(){
        table = layui.table;
        $ =layui.jquery;
        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：https://www.layui.com/doc/modules/table.html#totalRow
        table.render({
            elem: '#test'
            ,url:'/courseorder/listJson'
            ,toolbar: '#toolbarDemo'
            ,title: '用户数据表'
            ,totalRow: true
            ,cols: [
                [
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                ,{field:'name', title:'名字', width:120, edit: 'text'}
                ,{field:'wechat_mark', title:'微信备注', width:120, edit: 'text'}
                ,{field:'wechat_no', title:'微信ID', width:120, edit: 'text'}
                ,{field:'qq_no', title:'QQ号', width:120, edit: 'text'}
                ,{field:'course_name', title:'购买课程', width:120, edit: 'text'}
                ,{field:'course_price', title:'价格', width:120, edit: 'text'}
                ,{field:'course_date', title:'订单日期', width:120, edit: 'text'}
                ,{fixed: 'right', title:'操作', toolbar:'#barDemo' , width:150}
            ]
            ]
            ,page: true
            ,limit:7
            ,limits:[7,8,9,10],
            id:'orderTable'
        });

        //工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                    break;
                case 'add':
                    //layer.msg('添加');
                    parent.layer.open({
                        type:2,//2跳转到页面
                        offset:'auto',
                        content:'/courseorder/toadd',
                        title:'添加课程订单',
                        area:['1000px','650px'],
                        btn:'关闭全部',
                        btnAlign:'c',
                        yes:function () {
                            parent.layer.closeAll();
                        }
                    });
                    break;
            };
        });
//工具条事件
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var orderId = obj.data.order_id; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            // var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            console.log(layEvent);
            if(layEvent === 'del'){ //查看
                //do somehing
                layer.confirm('真的删除行么', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    //向服务端发送删除指令
                    $.get("/courseorder/delete",{order_id:orderId},function (result) {
                        console.log(result);
                    })
                });
            }else if(layEvent === 'edit'){ //编辑
                //do something
                parent.layer.open({
                    type:2,
                    offset:'auto',
                    title:'课程订单修改',
                    content:'courseorder/edit?order_id='+ orderId,
                    area:['1000px','500px'],
                    btn:'全部关闭',
                    btnAlign:'c',
                    yes:function(){
                        parent.layer.closeAll();
                    }

                });
                //同步更新缓存对应的值
                obj.update({
                    username: '123'
                    ,title: 'xxx'
                });
            } else if(layEvent === 'LAYTABLE_TIPS'){
                layer.alert('Hi，头部工具栏扩展的右侧图标。');
            }
        });



        table.on('rowDouble(test)', function(obj){
            //obj 同上
            //console.log(obj);
            var orderId=obj.data.order_id;
            parent.layer.open({
                type:2,
                offset:'auto',
                title:'课程订单详情',
            content:'courseorder/detail?order_id='+ orderId,
                area:['1000px','500px'],
                btn:'全部关闭',
                btnAlign:'c',
                yes:function(){
                    parent.layer.closeAll();
                }

            })

        });

    });
function doSerach() {
    var wechat_no=$('#wechat_no').val();
    var wechat_mark=$('#wechat_mark').val();
    var qq_no=$('#qq_no').val();


    table.reload('orderTable',{
        where:{
            wechat_no: wechat_no,
            wechat_mark:wechat_mark,
            qq_no:qq_no
        },
        page:{
            curr:1//搜索跳回第一页
        }
    });
}
</script>

</body>
</html>
